<?php

class SizenameApp extends MemberbaseApp
{
	var $_sizename_mod;
    function __construct()
    {
        $this->SizenameApp();
    }
    function SizenameApp()
    {
        parent::__construct();
		$this->_sizename_mod =& m('sizename');
    }
	
    function index()
    {

		$page = $this->_get_page();
		$sizenames = $this->_sizename_mod->find(array(
			'order' => 'snid ASC',
			'count' => true,
			'limit' => $page['limit']
		));
		$page['item_count'] = $this->_sizename_mod ->getCount();
		$this->_format_page($page);
		$this->assign('page_info', $page);
		$this->assign('sizenames', $sizenames);
        $this->display('sizename.index.html');
        /* 当前位置 */
        $this->_curlocal(LANG::get('sizename_manage'));
    }
	
	function add()
	{
		if (!IS_POST) {
	        $this->display('sizename.form.html');
        	/* 当前位置 */
        	$this->_curlocal(LANG::get('sizename_manage'), 'index.php?app=sizename',
				Lang::get('添加尺寸名称'));
		} else {
			$v1_name = isset($_POST['v1_name'])?trim($_POST['v1_name']):"";
			$v2_name = isset($_POST['v2_name'])?trim($_POST['v2_name']):"";
			$v3_name = isset($_POST['v3_name'])?trim($_POST['v3_name']):"";
			$v4_name = isset($_POST['v4_name'])?trim($_POST['v4_name']):"";
			$v5_name = isset($_POST['v5_name'])?trim($_POST['v5_name']):"";
			$v6_name = isset($_POST['v6_name'])?trim($_POST['v6_name']):"";
			
			if (empty($v1_name)||empty($v2_name)||empty($v3_name)||empty($v4_name)||empty($v5_name)||empty($v6_name)) {
				$this->show_warning('sizename_not_empty');
				return;
			}

			
			$data = array(
				'v1_name' => $v1_name,
				'v2_name' => $v2_name,
				'v3_name' => $v3_name,
				'v4_name' => $v4_name,
				'v5_name' => $v5_name,
				'v6_name' => $v6_name,
			);
			
			$snid = $this->_sizename_mod ->add($data);
			if (!$snid) {
				$this->_error($this->_sizename_mod ->get_error());
				return;
			}
			$this->show_message('添加尺寸名称成功', Lang::get('sizename_manage'), 'index.php?app=sizename');
		}
	}
	
	
	function edit()
	{
		$snid = intval($_GET['snid']);
		if (!$snid) {
			$this->show_warning('尺寸名称不存在');
		}
		if (!IS_POST) {
			$sizename = $this->_sizename_mod ->get_info($snid);
			$this->assign('sizename', $sizename);
			
	        $this->display('sizename.form.html');
        	/* 当前位置 */
        	$this->_curlocal(LANG::get('sizename_manage'), 'index.php?app=sizename',
				Lang::get('编辑尺寸名称'));
		} else {
			$v1_name = isset($_POST['v1_name'])?trim($_POST['v1_name']):"";
			$v2_name = isset($_POST['v2_name'])?trim($_POST['v2_name']):"";
			$v3_name = isset($_POST['v3_name'])?trim($_POST['v3_name']):"";
			$v4_name = isset($_POST['v4_name'])?trim($_POST['v4_name']):"";
			$v5_name = isset($_POST['v5_name'])?trim($_POST['v5_name']):"";
			$v6_name = isset($_POST['v6_name'])?trim($_POST['v6_name']):"";
			
			if (empty($v1_name)||empty($v2_name)||empty($v3_name)||empty($v4_name)||empty($v5_name)||empty($v6_name)) {
				$this->show_warning('sizename_not_empty');
				return;
			}

			
			$data = array(
				'v1_name' => $v1_name,
				'v2_name' => $v2_name,
				'v3_name' => $v3_name,
				'v4_name' => $v4_name,
				'v5_name' => $v5_name,
				'v6_name' => $v6_name,
			);
			
			$this->_sizename_mod ->edit($snid, $data);
			if ($this->_sizename_mod ->get_error()) {
				$this->_error($this->_sizename_mod ->get_error());
				return;
			}
			$this->show_message('编辑尺寸名称成功', Lang::get('sizename_manage'), 'index.php?app=sizename');
		}
	}

	function del()
	{
		$snid = intval($_GET['snid']);
		if (!$snid) {
			$this->show_warning('尺寸名称不存在');
			return;
		}

		$this->_sizename_mod ->drop("snid={$snid}");
		if ($this->_sizename_mod ->get_error()) {
			$this->_error($sizename_mod->get_error());
			return;
		}
		
		$this->show_message('删除尺寸名称成功', Lang::get('sizename_manage'), 'index.php?app=sizename');
		
	}

}

?>
